package com.cmq.web_1.employeemanage;


import com.cmq.web_1.employeemanage.EmployeeDAO;
import com.cmq.web_1.employeemanage.EmployeeDAOImpl;
import com.cmq.web_1.employeemanage.User;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/employeemanage/dashboard")
public class DashboardServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private EmployeeDAO employeeDAO;

    public void init() {
        employeeDAO = new EmployeeDAOImpl();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取登录用户信息
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");

        if (user == null) {
            // 如果用户未登录，重定向到登录页面
            response.sendRedirect("/employeemanage/login");
            return;
        }

        // 获取员工列表
        request.setAttribute("employees", employeeDAO.getAllEmployees());
        request.setAttribute("user", user);

        // 转发到仪表盘页面
        request.getRequestDispatcher("/employeemanage/dashboard.jsp").forward(request, response);
    }
}